/**
 * The Anagram class represents methods which are prepare and comparison for two
 * phrases.
 * 
 * @author Sergii Serba
 * @version 0.0, 27/01/2013
 * 
 */
public class Anagram {
	/**
	 * This method converts the phrase into word.
	 */
	private static String[] prepare(String[] phrase) {
		String space = "([\\s])";
		String distance = "";
		phrase[0] = phrase[0].toLowerCase().replaceAll(space, distance);
		phrase[1] = phrase[1].toLowerCase().replaceAll(space, distance);
		return phrase;
	}
	/**
	 * This method compares the words.
	 */
	private static void comparison(String[] word) {
		char[] firstWord = word[0].toCharArray();
		char[] secondWord = word[1].toCharArray();
		if (firstWord.length == secondWord.length) {
			int x = 0;
			int i = 0;

			while ((i < firstWord.length) && (x < firstWord.length)) {

				if (firstWord[x] == secondWord[i]) {
					if (x == firstWord.length - 1) {
						System.out.println("Yes, it's anagram");
					}
					firstWord[x] = 0;
					secondWord[i] = 0;

					x++;
					i = 0;

				} else
					i++;
			}
			if (x != firstWord.length) {
				System.out.println("No, it's anagram");
			}
		} else {
			System.out.println("No, it's not anagram");
		}
	}

	public static void main(String[] args) {
		Anagram ob = new Anagram();
		ob.comparison(ob.prepare(args));
	}
}
